-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(source): refine source macro #12260
Conversation
Codecov Report
@@ Coverage Diff @@
## main #12260 +/- ##
=======================================
Coverage 69.73% 69.74%
=======================================
Files 1424 1424
Lines 236449 236444 -5
=======================================
+ Hits 164888 164897 +9
+ Misses 71561 71547 -14
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally LGTM, thanks for the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your effort! Great work!
Does this PR help mitigate this issue? 🤔 |
macro_rules! dispatch_source_prop { | ||
($impl:expr, $source_prop:tt, $body:expr) => {{ | ||
use $crate::source::ConnectorProperties; | ||
$crate::dispatch_source_enum! {ConnectorProperties, { $impl }, {$source_prop, IgnorePropType, IgnoreSplitType}, {$body}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I revisit this pr to want to understand how does dispatch_source_prop!
work, but it is hard to get it. Because these macros are nested instead of in a flatten structure.
For example to understand the third arg {$source_prop, IgnorePropType, IgnoreSplitType}
, I need to dive into other macros level by level. What's worse is that IDE can't expand these macro_rules!
directly without calling it in a function. Is there a way to show the expanded code of a macro_rules!
without calling it just like a function definition? Or coud we flatten these macros a bit? cc @wenym1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to show the expanded code of a macro_rules! without calling it just like a function definition
You can write an example in a random function and use cargo expand
to see the expanded code.
coud we flatten these macros a bit
This main idea of this PR is to declare all source related information in only one place so that when developing a new source, we don't have to declare these information in places previously scattered around in our codebase.
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
In our current code, we have many codes that define the whole method in macro to leverage the ability of list expansion inside macro to enumerate over all sources in a match statement, which is hard to read and debug, and the IDE has problem doing indexing on the code in the macro. Besides, when we want to support a new source, we need to add the new source to the list of both
properties
andsplit
(before the previous refactor we even need to add to the list ofreader
andenumerator
), which is somehow verbose.In this PR, all sources are declared in a single macro
for_all_classified_sources
with the following definition.Based on
for_all_classified_sources
, we reimplement the currentdispatch_source_prop
macro for enumeratingConnectorProperties
enum, and implementdispatch_split_impl
macro for enumeratingSplitImpl
. With these macros, many methods ofConnectorProperties
andSplitImpl
previously defined in macro can be implemented in the same way as normal methods. When we want to support a new source, we only need to add its information in thefor_all_classified_sources
macro.The end of a series of source refactor. PRs before:
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.